const path = require("path");
const { CleanWebpackPlugin } = require("clean-webpack-plugin");

module.exports = {
  entry: {
    app: "./src/app.js",
    "pages/index/index": "./src/pages/index/index.js",
  },
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "[name].js",
  },
  module: {
    rules: [
      {
        test: /\.scss$/,
        use: [
          {
            loader: "file-loader",
            options: {
              name: "[path][name].wxss",
              context: "src",
            },
          },
          "extract-loader",
          {
            loader: "css-loader",
            options: {
              importLoaders: 1,
              esModule: false, // 禁用 ES 模块语法
              modules: {
                mode: "icss", // 替代原来的 compileType
              },
            },
          },
          "postcss-loader",
          {
            loader: "sass-loader",
            options: {
              implementation: require("sass"),
              sassOptions: {
                //   fiber: require("fibers"),
              },
            },
          },
        ],
      },
      {
        test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
        type: "asset/resource",
        generator: {
          filename: "styles/iconfont/[name][ext]",
          publicPath: "/styles/iconfont/",
        },
      },
    ],
  },
  plugins: [new CleanWebpackPlugin()],
};
